package com.donger.business.form.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.donger.business.form.entity.SysFormData;
import com.donger.business.form.service.SysFormDataService;
import com.donger.common.core.utils.Res;
import com.donger.common.core.utils.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author 7326
 */
@RestController
@RequestMapping("/form/data")
@AllArgsConstructor
public class SysFormDataController {

    private final SysFormDataService sysFormDataService;


    /**
     * code 表单编码
     * version 表单版本
     *
     * @param page 分页
     * @return 表单对应数据
     */
    @GetMapping("/page/{code}")
    public Result page(Page page,@PathVariable("code")String code){
        IPage iPage = sysFormDataService.pageList(page, code);
        return Res.ok(iPage);
    }

    @GetMapping("/info/{id}")
    public Result info(@PathVariable("id") Long id) {
        SysFormData sysFormData = sysFormDataService.getById(id);
        return Res.ok(sysFormData);
    }

    @PostMapping("/save")
    public Result save(@RequestBody SysFormData sysFormData){
        sysFormDataService.save(sysFormData);
        return Res.ok();
    }

    @PostMapping("/update")
    public Result update(@RequestBody SysFormData sysFormData) {
        sysFormDataService.updateById(sysFormData);
        return Res.ok();
    }

    @DeleteMapping("/del/{id}")
    public Result delete(@PathVariable("id") Long id) {
        sysFormDataService.removeById(id);
        return Res.ok();
    }
}
